package ca.concordia.soen6461.wichf.ui.web.parser;

import javax.servlet.http.HttpServletRequest;

import ca.concordia.soen6461.wichf.controller.Session;
import ca.concordia.soen6461.wichf.navigation.event.CheckoutEvent;
import ca.concordia.soen6461.wichf.ui.web.BaseEventParser;

public class CheckoutEventParser extends BaseEventParser<CheckoutEvent> {

	public CheckoutEventParser() {
		super(CheckoutEvent.class);
	}

	@Override
	public CheckoutEvent parse(HttpServletRequest request, Session session) {
		CheckoutEvent event = new CheckoutEvent(session);
		populateEvent(request, event);
		return event;
	}

	public static void populateEvent(HttpServletRequest request, CheckoutEvent event) {
		for (String parameter : request.getParameterMap().keySet()) {
			if (parameter.startsWith("item.")) {
				int item = Integer.parseInt(parameter.substring("item.".length()));
				event.getSelectedAppointments().add(item);
			}
		}
	}

}
